package com.sky.zero.dict.service;

import com.sky.zero.common.generate.core.base.BaseService;
import java.util.List;
import java.util.Collections;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.bean.BeanUtil;

import com.sky.zero.dict.entity.Dict;
import com.sky.zero.dict.entity.DictParam;
import com.sky.zero.dict.entity.DictVO;
import com.sky.zero.dict.mapper.DictMapper;


@Slf4j
@Service
@Transactional(readOnly = true)
public class DictService extends BaseService {

	@Autowired
	private DictMapper dictMapper;

    /** 查询列表(分页)**/
    public PageInfo<DictVO> getDictPage(DictParam param){
		param.enablePage();
		return toPageInfo(dictMapper.findList(param),DictVO.class);
	}

    /** 查询列表**/
    public List<DictVO> getDictList(DictParam param) {
		 return copyToList(dictMapper.findList(param), DictVO.class);
	}

    /** 根据ID获取详情**/
    public DictVO getDictById(Integer id) {
		return BeanUtil.toBean(dictMapper.findById(id), DictVO.class);
	}

    /** 新增**/
    @Transactional
    public Integer insertDict(Dict dict) {
		return insertBatchDict(Collections.singletonList(dict));
	}

    /** 批量新增**/
    @Transactional
    public Integer insertBatchDict(List<Dict> dictList) {
		return dictMapper.insertBatch(dictList);
	}

    /** 更新**/
    @Transactional
    public Integer updateDict(Dict dict) {
		  return updateBatchDict(Collections.singletonList(dict));
	}

    /** 批量更新**/
    @Transactional
    public Integer updateBatchDict(List<Dict> dictList) {
		  return dictMapper.updateBatch(dictList);
	}

    /** 根据ID删除**/
    @Transactional
    public Integer delDictById(Integer id) {
	  return delDictByIds(Collections.singletonList(id));
	}

    /** 根据ID批量删除**/
    @Transactional
    public Integer delDictByIds(List<Integer> ids) {
		return dictMapper.delByIds(ids);
	}

}